clear all


*===================== Globals with folder locations ===========================

global projectdir "PROJECT-FOLDER"		   				// replace as appropriate
global codedir    "${projectdir}\Code"
global datadir    "${projectdir}\Dataset"
global tabledir   "${projectdir}\Table"
global figuredir  "${projectdir}\Figure"

global datadir_el      "EQUITY-LOAN-DATA-FOLDER"		// replace as appropriate
global datadir_psd     "MORTGAGE-DATA-FOLDER"			// replace as appropriate
global datadir_landreg "HOUSE-TRANSACTIONS-DATA-FOLDER"	// replace as appropriate
global datadir_hpindex "HOUSE-PRICE-INDICES-DATA-FOLDER"// replace as appropriate
global datadir_plookup "POSTCODE-REGION-LOOKUP-FOLDER"  // replace as appropriate
global datadir_epc     "EPC-DATA-FOLDER"				// replace as appropriate
global datadir_nmg     "NMG-DATA-FOLDER"				// replace as appropriate
global datadir_shp     "UK-SHAPEFILE-FOLDER"			// replace as appropriate



*================= Packages and ad-hoc programs (functions) ====================

capture ssc install estout
capture ssc install reghdfe
capture ssc install ftools		
capture ssc install tuples		
capture ssc install rdrobust
capture ssc install spmap
capture ssc install shp2dta
    
do "${codedir}\00_function.do" // some helper functions



*=========================== Data preparation ==================================

// Open files
do "${codedir}\01_open_EL.do"	  // Equity loans
do "${codedir}\01_PSD_001.do"	  

do "${codedir}\01_prepare_placebo_PSD001_2009-2012.do"	  

do "${codedir}\01_prepare_la_region_postcode_lookup.do"
do "${codedir}\01_prepare_la_region_postcode_lookup_2018.do"

do "${codedir}\01_prepare_local_price_appreciation.do"
do "${codedir}\01_prepare_local_price_appreciation_2020.do"

do "${codedir}\01_open_land_registry.do"
do "${codedir}\01_open_land_registry_2020.do"	  

do "${codedir}\01_prepare_epc.do"

do "${codedir}\01_prepare_map.do"	  


// Merge and other steps
do "${codedir}\02_open_merge_EL_redemptions.do"

do "${codedir}\02_prepare_prevnew_index.do"	    

do "${codedir}\03_merge_EL_PSD001.do"	 

do "${codedir}\03_merge_EL_LandRegistry.do"     		            
do "${codedir}\03_merge_EL_LandRegistry_2020.do"     		            

do "${codedir}\04_prepare_PSD001_remortgages_EL.do"     		            

do "${codedir}\04_prepare_noEL_counterfactual.do"

do "${codedir}\04_LandReg_repeatsales_newhomes.do"

do "${codedir}\04_prepare_match_sqm.do"




*============== Analysis Section 3: The demand for equity loans ================



*--- 3.1 Mortgage origination characteristics

// Table 1: Comparison of equity loan and non-equity loan borrowers
// Table A2, A3, A6-A9
do "${codedir}\04_table_summary_stat.do"	      		

// Figure 2: Loan to value and loan to income
// Figure A8, Table A5
do "${codedir}\04_result1_HTBconstrained.do"

// Table A4
do "${codedir}\04_result1_HTBconstrainedPTI.do"

// Figure A7
do "${codedir}\04_age_income_dist.do"
* 01_prepare_USoc.R
* 02_USoc_age_income.R

// Information on checking account balances from credit reference agency
* 01_cra_home_buyer-match.R
* 02_cra_home_buyer-stats.R

// Information on down payments
do "${codedir}\04_check_downpayment.do"



*--- 3.2 Bunching and selection at the maximum property price

// Figure 3: Bunching of property prices: London
// Figure 4: Selection around the £600,000 limit in London: Borrower characteristics
// Figure 5: Selection around the £600,000 limit in London: Leverage
// Figure 6: Selection around the £600,000 limit in London (Placebo: existing houses)
// Figure A9-A11
do "${codedir}\04_bunching_600k.do"



*--- 3.3 EL as complement or substitute? The London experiment

// Figure 7: House prices in the South East of England and London. Down payment to value and equity loan to value distribution
do "${codedir}\04_England_London_house_prices.do"
do "${codedir}\04_figure_London_DTV_ETV.do"


// Table 2: Effect of the introduction of the London equity loan scheme
// Figure 8: London vs the South East of England: dependent variables
// Table A10, Figure A12-A13
do "${codedir}\05_result1_London_diff_in_diff.do"
do "${codedir}\05_result1_borderanalysis.do"



*--- 3.4 Equity loan versus debt with a government guarantee

// Figure 9: Mortgage payments with equity loan compared to mortgage guarantee
do "${codedir}\05_equityproduct_htbVSguarantee.do"

// Figure 10 [EXCEL]: Borrower income and property purchase price for acquisitions financed with the equity loan and a mortgage guarantee
* Statistics_MGS_EL.xlsx



*=========== Analysis Section 4: Equity loan repayment and returns =============


*--- 4.1 Selection into equity loan repayment 

// Figure 11: Cumulative redemptions
// Table A16
do "${codedir}\04_EL_redemptions_survival_chart.do" 
do "${codedir}\04_EL_redemptions_sumstat.do" 


// Figure 12: House appreciation, income growth and equity extraction
// Figure 13: Local area vs individual house appreciation by equity loan outcome
// Figure A16
do "${codedir}\05_EL_redemptions_analyse"



*--- 4.2 Implications for equity provider returns

// Table 3: Equity provider returns
do "${codedir}\04_equityreturn.do" 

// Table 4: House price effect: equity loan vs non-equity loan within new homes
do "${codedir}\04_price_effect_regressions.do" 

// Table 5: Property valuation and returns after equity loan repayment
do "${codedir}\04_Returns_after_repayment_actual.do" 
do "${codedir}\04_Returns_after_repayment_potential.do" 



*--- 4.3 Future property returns after equity loan repayment

// Table 6: Local area returns after equity loan repayment
do "${codedir}\04_la_returns_afer_repayment.do" 



*--- 4.4 Ex-post borrower monetary gains/losses

// Figure 14: Interest rate and break-even house price appreciation (2-year fixed)
do "${codedir}\05_noEL_interest_break-even_charts.do" 

// Table 7: Difference in ex-post wealth with EL
do "${codedir}\05_noEL_moneyleft_sumstat.do" 


// Table A13, A15
// Figure A14
do "${codedir}\05_noEL_interest_payments.do" 
do "${codedir}\05_noEL_stats_quartile_breakeven.do" 





*============= Analysis Section 5: Mortgage refinancing frictions ==============


*--- 5.2 Refinancing behavior

// Table 8: Refinancing probability
do "${codedir}\04_remortgage_likelihood.do" 

// Table 9: Time to refinancing
do "${codedir}\04_remortgage_likelihood_bycohort.do" 

// Figure A15, A17-A18
do "${codedir}\05_remortgage_breakevenhp_withfrictions.do"
do "${codedir}\05_remortgage_holdingperiod.do"
do "${codedir}\04_remortgage_fixedperiod_choice.do"




*==================== Additional Analysis in the Appendix =====================

*--- Appendix A: Equity IRR for the government 

// Figure A1
* EquityLoanIRR.xlsx


*--- Appendix B: A simple framework

// Figure A2-A6
* Framework.xlsx


*--- Appendix G: Evidence on expectations

// Table A11: Extrapolative expectations
do "${codedir}\02_open_NMG_match_la.do"
do "${codedir}\03_extrapolative_expectations_dataprep.do"
do "${codedir}\04_extrapolative_expectations_reg.do"
